package cn.kmust.booth.portal.controller;




import cn.kmust.booth.portal.service.IAreaService;
import cn.kmust.booth.portal.vo.AreaVO;
import cn.kmust.booth.portal.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2020-08-08
 */
@RestController
@RequestMapping("/api/v1/areas")
public class AreaController {
    @Autowired
    private IAreaService areaService;

    //http://localhost:8080/api/v1/areas/findnumber/2
    @RequestMapping("/findnumber/{id}")
    public R<Integer> findnumber(@PathVariable("id") Integer id){
        Integer num = areaService.findnumber(id);
        return R.ok(num);
    }

    //http://localhost:8080/api/v1/areas/findtotal/2
    @RequestMapping("/findtotal/{id}")
    public R<Integer> findtotal(@PathVariable("id") Integer id){
        Integer num = areaService.findtotal(id);
        return R.ok(num);
    }

    //http://localhost:8080/api/v1/areas/findusenumber/2
    @RequestMapping("/findusenumber/{id}")
    public R<Integer> findusenumber(@PathVariable("id") Integer id){
        Integer num = areaService.findusenumber(id);
        return R.ok(num);
    }

    //建国
    //http://localhost:8081/api/v1/areas/add?total=1200&number=10&localInfo=111&flag=1&openTime=7:00:00&closeTime=11:00:00&userId=1
    @RequestMapping("/add")
    public R<Void> add(AreaVO areaVO, Integer userId, @RequestParam(value = "openTime",required = false) String openTime, @RequestParam(value = "closeTime",required = false) String closeTime){
        areaService.add(areaVO,userId,openTime,closeTime);
        return R.ok();
    }

    //http://localhost:8081/api/v1/areas/delete?id=1&userId=1
    @RequestMapping("/delete")
    public R<Void> delete(Integer id,Integer userId){
        areaService.delete(id,userId);
        return R.ok();
    }

    //http://localhost:8081/api/v1/areas/update??total=1100&number=11&localInfo=111&flag=1&openTime=7:00&closeTime=11:00&id=4&userId=1
    @RequestMapping("/update")
    public R<Void> update(AreaVO areaVO,Integer id,Integer userId,String startTime,String endTime){
        areaService.update(areaVO,id,userId,startTime,endTime);
        return R.ok();
    }
}
